<template>
  <div class="address">
    <el-select
      v-model="selectAddress.selectProvince"
      placeholder="请选择省"
      clearable
    >
      <el-option
        v-for="item in provinces"
        :key="item.id"
        size="mini"
        :label="item.name"
        :value="item.id"
        @click.native="changeProvince(item.id)"
      />
    </el-select>
    <el-select
      v-model="selectAddress.selectCity"
      placeholder="请选择市"
      clearable
      style="margin:0 8px"
    >
      <el-option
        v-for="item in cities"
        :key="item.value"
        size="mini"
        :label="item.name"
        :value="item.id"
        @click.native="changeCity(item.id)"
      />
    </el-select>
    <el-select
      v-model="selectAddress.selectArea"
      placeholder="请选择区"
      clearable
    >
      <el-option
        v-for="item in area"
        :key="item.value"
        size="mini"
        :label="item.name"
        :value="item.id"
      />
    </el-select>
  </div>
</template>

<script>
import { getCityApi, getProvinceApi } from '@/api/ogization'
export default {
  data() {
    return {
      provinces: '',
      cities: '',
      area: '',
      selectAddress: {
        selectProvince: '',
        selectCity: '',
        selectArea: ''
      }

    }
  },
  created() {
    this.getProvince()
  },
  methods: {
    // 获取省份
    async getProvince() {
      this.provinces = await getProvinceApi()
    },
    // 获取城市
    async changeProvince(id) {
      const res = await getCityApi(id)
      this.cities = res
      this.selectAddress.selectCity = ''
      this.selectAddress.selectArea = ''
    },
    // 获取地区
    async changeCity(id) {
      const res = await getCityApi(id)
      this.selectAddress.area = res
      this.selectAddress.selectArea = ''
    }
  }

}
</script>

<style lang="scss" scoped>
.address{
  display: flex;
}
</style>
